﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using uPLibrary.Networking.M2Mqtt;
using System.Net;
using uPLibrary.Networking.M2Mqtt.Messages;
using Microsoft.Win32;

namespace LindeRmtDigDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        private void ClickConnectServer(object sender, RoutedEventArgs e)
        {
            wWorkWindow WorkWindow = new wWorkWindow();
            WorkWindow.ShowDialog();
            WorkWindow.Close();
        }

        private void ClickSaveConfigFile(object sender, RoutedEventArgs e)
        {
            SaveFileDialog SettingFilePathFd = new SaveFileDialog();
            SettingFilePathFd.Filter = @"配置文件|*.ini;";
            SettingFilePathFd.ShowDialog();
            string SettingFilePath = SettingFilePathFd.FileName;
            OperateConfigFile.SetValue("HostName", sHostName.Text, SettingFilePath);
            OperateConfigFile.SetValue("HostPort", sServerPort.Text, SettingFilePath);
            OperateConfigFile.SetValue("SubcribeTopicName", sSubscribeTopic.Text, SettingFilePath);
            OperateConfigFile.SetValue("PublishTopicName", sPublishTopic.Text, SettingFilePath);
        }

        private void ClickLoadConfigFlie(object sender, RoutedEventArgs e)
        {
            OpenFileDialog SettingFilePathFd = new OpenFileDialog();
            SettingFilePathFd.Filter = @"配置文件|*.ini;";
            SettingFilePathFd.ShowDialog();
            string SettingFilePath = SettingFilePathFd.FileName;
            sHostName.Text = OperateConfigFile.GetValue("HostName", SettingFilePath);
            sServerPort.Text = OperateConfigFile.GetValue("HostPort", SettingFilePath);
            sSubscribeTopic.Text = OperateConfigFile.GetValue("SubcribeTopicName", SettingFilePath);
            sPublishTopic.Text = OperateConfigFile.GetValue("PublishTopicName", SettingFilePath);           
        }
    }
}
